/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 言初
 * Date: 2023-03-10
 * Time: 12:17
 */
public class Rectangle {
    private Point leftTop;
    private Point rightTop;
    private Point leftFloor;
    private Point rightFloor;

    private double cincum;//周长
    private double area;//面积
    public Rectangle(){
        this.leftTop=new Point(0.0,0.0);
        this.rightTop=new Point(0.0,0.0);
        this.leftFloor=new Point(0.0,0.0);
        this.rightFloor=new Point(0.0,0.0);
    }
    public Rectangle(double x1,double y1,double x2,double y2){
        //找对角线，放进去
        if(x1>x2){
            if(y1>y2){
                this.rightTop=new Point(x1,y1);
                this.leftFloor=new Point(x2,y2);
                //4个点的坐标都需要写出来
                this.leftTop=new Point(x2,y1);
                this.rightFloor=new Point(x1,y2);
            }else{
                this.rightFloor=new Point(x1,y1);
                this.leftTop=new Point(x2,y2);
                //4个点的坐标都需要写出来
                this.rightTop=new Point(x1,y2);
                this.leftFloor=new Point(x2,y1);
            }
        }else{
            if(y1>y2){
                this.leftTop=new Point(x1,y1);
                this.rightFloor=new Point(x2,y2);
                //4个点的坐标都需要写出来
                this.leftFloor=new Point(x1,y2);
                this.rightTop=new Point(x2,y1);
            }else{
                this.leftFloor=new Point(x1,y1);
                this.rightTop=new Point(x2,y2);
                //4个点的坐标都需要写出来
                this.leftTop=new Point(x1,y2);
                this.rightFloor=new Point(x2,y1);
            }
        }

    }

    public Rectangle(Point p1,Point p2){
        double x1=p1.getX();
        double y1=p1.getY();
        double x2=p2.getX();
        double y2=p2.getY();
        if(x1>x2){
            if(y1>y2){
                this.rightTop=new Point(x1,y1);
                this.leftFloor=new Point(x2,y2);
                //4个点的坐标都需要写出来
                this.leftTop=new Point(x2,y1);
                this.rightFloor=new Point(x1,y2);
            }else{
                this.rightFloor=new Point(x1,y1);
                this.leftTop=new Point(x2,y2);
                //4个点的坐标都需要写出来
                this.rightTop=new Point(x1,y2);
                this.leftFloor=new Point(x2,y1);
            }
        }else{
            if(y1>y2){
                this.leftTop=new Point(x1,y1);
                this.rightFloor=new Point(x2,y2);
                //4个点的坐标都需要写出来
                this.leftFloor=new Point(x1,y2);
                this.rightTop=new Point(x2,y1);
            }else{
                this.leftFloor=new Point(x1,y1);
                this.rightTop=new Point(x2,y2);
                //4个点的坐标都需要写出来
                this.leftTop=new Point(x1,y2);
                this.rightFloor=new Point(x2,y1);
            }
        }
    }

    public Point getLeftTop(){
        return leftTop;
    }
    public Point getLeftFloor(){
        return leftFloor;
    }
    public Point getRightTop(){
        return rightTop;
    }
    public Point getRightFloor(){
        return rightFloor;
    }

    public double getCincum(){
        if(rightFloor.getX()==leftTop.getX()){
            //或者是一个竖线
             return Math.abs(rightFloor.getY()-rightTop.getY());
        }
        if(leftFloor.getY()==rightTop.getY()){
            //如果是一条横线
            return Math.abs(rightFloor.getX()-leftFloor.getX());
        }

        double a=Math.abs(rightFloor.getX() - leftFloor.getX());
        double b=Math.abs(leftTop.getY()-leftFloor.getY());//在这里回头取一下绝对值
        cincum=a*2+b*2;
        return cincum;
    }
    public double getArea(){
        double a=Math.abs(rightFloor.getX() - leftFloor.getX());
        double b=Math.abs(leftTop.getY()-leftFloor.getY());//在这里回头取一下绝对值
        area=a*b;
        return area;
    }
}
